<template>
	<view class="sticky">
		<scroll-view scroll-y="true" @scrolltolower='scrolltolower' class="sticky-scroll" :style="{'height': listHeight+'px'}">
			<view class="sticky-scroll-container">
				<view class="top" v-if="list.length===0&&beginTime">
					<view class="flex flex-ai-c" @click="handle">
						<view class="text" @click="handle">{{returnTime(beginTime)}}月</view>
						<u-icon class="logo" name="arrow-down-fill" size="24" color="#999999"></u-icon>
					</view>
				</view>
				<view class="wrapper" v-for="(item, idx) in list" :key="idx">
					<view class="top">
						<view class="flex flex-ai-c width-50" @click="handle">
							<view class="text">{{beginTime===''?item.mon:returnTime(beginTime)}}月</view>
							<u-icon class="logo" name="arrow-down-fill" size="24" color="#999999"></u-icon>
						</view>
						<view class="width-50 u-text-right mr-10" @click="morestatus=!morestatus">
							全部状态
						</view>
						<!-- 更多列表 -->
						<view class="shadowWrap" v-if="morestatus">
							<view class="san"></view>
							<view class="shadow">
								<view class="list" v-for="(it,index) in statusList" :key='index' @click="changeStatus(it)">{{it.name}}</view>

							</view>
						</view>
					</view>
					<view class="item">
						<view class="item-info">
							<text>收入 ￥{{item.inmoney}}</text>
							<text class="spend">支出￥{{item.outmoney}}</text>
						</view>
						<view class="item-content">
							<view class="item-content__item" v-for="(datas, idx) in item.list" :key="idx" @click="toDetail(datas.id)">
								<view class="item-content__item-left">
									<text class="item-content__item-left-top">{{datas.store_name || '暂无'}}</text>
									<text class="item-content__item-left-bottom">
										<text>{{datas.addtime}}</text>
									</text>
								</view>
								<view class="item-content__item-right">
									<text class="item-content__item-right-top">{{datas.money}}</text>
									<!-- <text class="item-content__item-right-bottom">已全额退款</text> -->
								</view>
							</view>
						</view>
					</view>
					<view style="width: 100%; height: 30rpx;"></view>
				</view>
				<uni-load-more :status="more" iconType="circle"></uni-load-more>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue"
	
	export default {
		data() {
			return {
				nums: 0, //总条数
				max: 10, //每页显示条数
				timer: null,
				more: 'loading',
				container: null,
				allHeight: null,
				debounce: null,
				pageIndex: 1,
				totalPage: NaN,
				list: [],
				flag1: false,
				flag2: false,
				status:0,
				morestatus:false,
				statusList:[{id:0,name:'全部状态'},{id:1,name:'待审核'},{id:2,name:'已审核'},{id:3,name:'已拒绝'}]
			}
		},
		props: {
			listHeight: {
				type: Number,
				default: 1000,
			},
			type: {
				type: Number,
				default: 0
			}
		},
		computed: {
			beginTime(){
				return this.$store.state.user.beginTime
			},
			endTime(){
				return this.$store.state.user.endTime
			},
			isRefresh(){
				return this.$store.state.user.isRefresh
			}
		},
		watch: {
			/* isRefresh(val){
				if(val){
					this.flag1 = false;
					this.flag2 = false;
					this.pageIndex = 1;
					this.more = 'loading',
					this.scrolltolower()
					this.$store.commit('user/setIsRefresh',false)
				}
			}, */
			type(val){
				if(this.type !== 3){
					this.totalPage = NaN;
					this.$store.state.user.beginTime = ''
					this.$store.state.user.endTime = ''
					this.list = [];
					this.pageIndex = 1;
					this.getList()
				}
			},
		},
		created () {
			// this.getList()
		},
		methods: {
			changeStatus(data){
				this.status=data.id
				this.list=[]
				this.getList()
			},
			returnTime(time) {
			  if (time) {
			    return time.split('-')[1]
			  }
			},
			scrolltolower(){
				this.getList()
			},
			handle () {
				this.$emit('handle')
			},
			
			toDetail(id) {
				uni.navigateTo({
					url: '/pages_common/pages_me/assets/billDetail/billDetail?id='+id
				})
			},		
			// 加载前、中、后
			moreStatus(status) {
			  this.more = status
			},
			getList() {
				uni.showLoading({
					title:'加载中',
					mask:true
				})
				this.more = 'loading'
				this.$api.user.getAssetsList({
					PageIndex: this.pageIndex,
					PageSize: 10,
					storeid: this.$store.state.userInfoDetail.store.storeId,//"f7a12a6149e14787b194fa323982bed8",
					begintime: this.beginTime,
					endtime: this.endTime,
					type: this.type,
					status:this.status
				}).then(res => {
					uni.hideLoading()
					this.totalPage = res.data.total;
					this.list = [...this.list, ...res.data.list]
					if (res.data.total <= 10) {
					  this.more = 'nomore'
					} else {
					  this.moreStatus(res.data.list.length !== 0 ? 'loadmore' : 'nomore')
					}
					if (res.data.list.length === 0) return false
					this.pageIndex += 1 // 当前页加1
					
				}).catch(e => {
					uni.hideLoading()
				})
			}
		},
		components: {
			uniLoadMore
		}
	}
</script>

<style lang="scss" scoped>
.sticky {
	width: 100%;
	// height: 100%;
	font-family: PingFang SC;
	&-scroll {
		// height: 100%;
		&-container {
			.wrapper {
			}
			.top {
				position: sticky;
				top: 0;
				display: flex;
				background-color: rgb(246, 246, 246);
				.text {
					font-size: 30rpx;
					font-weight: bold;
					color: #333333;
				}
				.logo {
					margin-left: 20rpx;
				}
			}
			.item {
				&-info {
					margin: 17rpx 0 30rpx 0;
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #656565;
					.spend {
						margin-left: 20rpx;
					}
				}
				&-content {
					background: #FFFFFF;
					box-shadow: 0px 0px 10rpx 0px rgba(0, 0, 0, 0.14);
					border-radius: 10rpx;
					padding: 0 20rpx;
					&__item {
						height: 128rpx;
						display: flex;
						justify-content: space-between;
						align-items: center;
						border-top: 2rpx solid #EEEEEE;
						font-family: PingFang SC;
						font-weight: 500;
						&:first-child {
							border: none;
						}
						&-left, &-right {
							display: flex;
							flex-direction: column;
						}
						&-left {
							&-top {
								font-size: 28rpx;
								color: #333333;
							}
							&-bottom {
								font-size: 26rpx;
								color: #999999;
								margin-top: 6rpx;
							}
						}
						&-right {
							text-align: right;
							&-top {
								font-size: 36rpx;
								font-weight: bold;
								color: #333333;
							}
							&-bottom {
								font-size: 26rpx;
								color: #EB5C02;
								font-weight: 500;
								margin-top: 6rpx;
							}
						}
					}
				}
			}
		}
	}
}
.shadowWrap {
	position: fixed;
	top: 270rpx;
	right: 20rpx;
	box-shadow:2px 2px 10px #999;
	border-radius: 20rpx;
	.shadow {
		width: 200rpx;
		background: #fff;
		opacity: 0.94;
		border-radius: 20rpx;
		color: #666;
		padding: 10rpx;
		.list {
			padding: 14rpx 30rpx;
			text-align: center;
		}
	}
	.san {
		width: 0;
		height: 0;
		border-left: 18rpx solid transparent;
		border-right: 18rpx solid transparent;
		border-bottom: 18rpx solid #fff;
		opacity: 0.94;
		position: absolute;
		right: 20rpx;
		top: -18rpx;
	}
}
</style>
